package com.fitso.web.service;

import java.text.DecimalFormat;
import java.text.NumberFormat;

import org.apache.log4j.Logger;

import com.fitso.model.bean.measure.length.Length;
import com.fitso.model.bean.measure.mass.Mass;
import com.fitso.model.calculator.BodyMassIndexCalculator;

public class BodyMassIndexCalculatorService extends DWRService {
	
	private static final Logger logger = Logger.getLogger(BodyMassIndexCalculatorService.class);

	private NumberFormat format = new DecimalFormat("#0.0");

	private BodyMassIndexCalculator _bmiCalculator;

	public void setBodyMassIndexCalculator(BodyMassIndexCalculator bmiCalculator) {
		_bmiCalculator = bmiCalculator;
	}

	public Double calculate(Length height, Mass weight) {
		logger.debug(String.format("height: %s - weight: %s", height, weight));
		return Double.valueOf(format.format(_bmiCalculator.calculate(height, weight)));
	}
}
